﻿
using BW.IDal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BW.Dal
{
    public class RoerlDal<T> : IBaerDal<T> where T : class
    {
         public RoerlDal(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> AddAnync(T t)
        {
             await Context.Set<T>().AddAsync(t);
              return await Context.SaveChangesAsync();


        }

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>
        public async  Task<int> AddRangeAnync(List<T> list)
        {
            await Context.Set<T>().AddRangeAsync(list);

            return await Context.SaveChangesAsync();
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>

        public async Task<int> DelteAnync(T t)
        {
             Context.Set<T>().Remove(t);


            return await Context.SaveChangesAsync();
        }


        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>
        public async  Task<int> DelteRaangAnync(List<T> list)
        {
            Context.Set<T>().RemoveRange(list);



            return await Context.SaveChangesAsync();
        }
        /// <summary>
        /// 延迟
        /// </summary>
        /// <returns>返回受影响行数</returns>

        public IQueryable<T> GetAllAnync()
        {
            return Context.Set<T>();

        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>

        public async  Task<int> UpdateAnync(T t)
        {
            Context.Set<T>().Update(t);
            return await Context.SaveChangesAsync();
        }
       

        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>

        public async Task<int> UpdateRangeAnync(List<T> list)
        {

            Context.Set<T>().UpdateRange(list);
            return await Context.SaveChangesAsync();

        }
    }
}
